package com.ben.xinyue.seckill.controller;

import com.ben.basic.exception.BaseResponse;
import com.ben.basic.exception.DefaultSuccessEnum;
import com.ben.xinyue.seckill.domain.entity.OrderInfo;
import com.ben.xinyue.seckill.domain.vo.GoodsVo;
import com.ben.xinyue.seckill.domain.vo.OrderDetailVo;
import com.ben.xinyue.seckill.service.GoodsService;
import com.ben.xinyue.seckill.service.OrderInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @ClassName: OrderController
 * @Description:  订单
 * @author: xinyue
 * @date: 2020/9/11 10:20 下午
 * @version: 1.0.0
 */
@RestController
@RequestMapping("order")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OrderController {

    private final OrderInfoService orderInfoService;
    private final GoodsService goodsService;

    @RequestMapping("/detail")
    @ResponseBody
    public BaseResponse<OrderDetailVo> info(@RequestParam("orderId") long orderId){
       OrderInfo orderInfo =  orderInfoService.getOrderById(orderId);
       if(Objects.isNull(orderInfo)){
            return BaseResponse.error("订单为空");
       }
       long goodsId = orderInfo.getGoodsId();
       GoodsVo goodsVo = goodsService.queryGoodsVoByGoodsId(goodsId);
       OrderDetailVo orderDetailVo = new OrderDetailVo();
       orderDetailVo.setGoods(goodsVo).setOrderInfo(orderInfo);
       return BaseResponse.business(DefaultSuccessEnum.SUCCESS, orderDetailVo);
    }

}
